//
// Created by taojiaheng on 2020/5/29.
//
#include "function.h"
/**
 * 秒转换纳秒
 * @param second 秒数 例如 5.4S =  5400000000
 * @return 纳秒
 */
unsigned long long secondToNanosecond(double second) {
    return (unsigned long long)1000000000 * second;
}

/**
 * 获取当前时间戳
 * @return 时间按
 */
long time() {
    time_t t;
    t = time(NULL);
    return t;
}

void printBuff(BUFF * buff, int mod){
    if(mod == 0) {
        // 字符串打印
        BUFF * temp_buff = new BUFF;
        temp_buff->buff = new char[buff->buff_len + 1];
        temp_buff->buff_len = buff->buff_len + 1;
        memcpy((void *)temp_buff->buff, (void *)buff->buff, buff->buff_len);
        temp_buff->buff[buff->buff_len] = '\0';
        printf("%s\n", temp_buff->buff);
        DEL_BUFF(temp_buff);
        return;
    }
    if(mod == 16) {
        int p = 0;
        for(int i = 0; i < buff->buff_len; i++) {
            printf("%0x ", buff->buff[i]);
            if(i == 0){p++; continue;}
            if(p % 10 == 0) printf("\n");
            p++;
        }
        return;
    }
    if(mod == 10) {
        int p = 0;
        for(int i = 0; i < buff->buff_len; i++) {
            printf("%d ", buff->buff[i]);
            if(i == 0){p++; continue;}
            if(p % 10 == 0) printf("\n");
            p++;
        }
    }
}